home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++ CDEV ƒ / UScanCDEV.cp < prev    next >
Encoding:
Text File  |  1991-08-24  |  2.2 KB  |  56 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    UScanCDEV.cp (MPW 3.2)
  3.  *    Copyright ©1991 David Kreindler.  All rights reserved.
  4.  *    
  5.  *    KNOWN BUGS AND SHORTCOMINGS:
  6.  *        TScanCDEV::DoHit() contains a hard-coded literal string; it should be stored as a resource
  7.  *        TScanCDEV::ScanDirectory() assumes that the volume being scanned is an HFS volume
  8.  *        the values of TScanCDEV::kDirectoryRect, TScanCDEV::kFileRect and TScanCDEV::kStatusRect are hard-coded; they should be stored as resources
  9.  */
  10.  
  11. #ifndef __PACKAGES__
  12. #include <Packages.h>
  13. #endif
  14.  
  15. #ifndef __TOOLUTILS__
  16. #include <ToolUtils.h>
  17. #endif
  18.  
  19. #ifndef __USCANCDEV__
  20. #include "UScanCDEV.h"
  21. #endif
  22.  
  23. const Rect TScanCDEV::kDirectoryRect = {17, 148, 31, 300};                                    // !!!
  24. const Rect TScanCDEV::kFileRect = {30, 148, 44, 300};                                        // !!!
  25. const Rect TScanCDEV::kStatusRect = {4, 148, 18, 300};                                        // !!!
  26.  
  27. void TScanCDEV::DoHit(short item, EventRecord *, long *cdevValue) {
  28.     if (item == ok) {
  29.         SetCursor(watchCursor);
  30.         ShowStatus("\pScanning");                                                            // !!!
  31.         ScanVolume();
  32.         EraseRect(&kDirectoryRect);                                                            // EraseRect() moves/purges memory, but these fields are static (stack-based), so this call should be safe
  33.         EraseRect(&kFileRect);
  34.         DoUpdate(cdevValue);
  35.     }
  36. }
  37.  
  38. void TScanCDEV::ScanDirectory(long directory) {
  39.     const short kDirectoryBit = 1 << 4;
  40.     short dirIndex = 1;
  41.     while (fCatalogInfo.hFileInfo.ioFDirIndex = dirIndex++,                                    // set the index field of the parameter block; increment our directory index (this is not part of the condition)
  42.            fCatalogInfo.hFileInfo.ioDirID = directory,                                        // set the directory field of the parameter block (this is not part of the condition either)
  43.            !PBGetCatInfo(&fCatalogInfo, false))                                                // get the directory’s catalog entry (this is the condition)
  44.         if (fCatalogInfo.hFileInfo.ioFlAttrib & kDirectoryBit) {                            // check to see if it is a directory
  45.             DoDirectory(fCatalogInfo);
  46.             ScanDirectory(fCatalogInfo.hFileInfo.ioDirID);                                    // recursively scan the contents of the current directory
  47.         }
  48.         else
  49.             DoFile(fCatalogInfo);
  50. }
  51.  
  52. void TScanCDEV::ScanVolume() {
  53.     fCatalogInfo.hFileInfo.ioVRefNum = 0;                                                    // scan the startup volume
  54.     fCatalogInfo.hFileInfo.ioNamePtr = fDirEntryName;                                        // give the file system someplace to put the entry’s name
  55.     ScanDirectory(fsRtDirID);
  56. }